#include "picpainter.h"
#include "open-simplex-noise.h"
#include <QDebug>
#include <QRect>

PicPainter::PicPainter(QWidget *parent)
    : QWidget(parent)
{


}

void PicPainter::paintEvent(QPaintEvent */*evet*/)
{
    QPainter painter(this);
    painter.setPen(Qt::NoPen);
    QSize size(5, 5);

    struct osn_context *ctx;
    open_simplex_noise(71567, &ctx);

    for(int x = 0; x < this->width(); x += size.width())
        for(int y = 0; y < this->height(); y += size.height())
        {
            double factor = (open_simplex_noise2(ctx, (double)x / 80, (double)y / 80) + 1) * 128;
            QColor brushColor;
            factor = qBound(0, (int)factor, 255);
            qDebug() << factor;
            brushColor.setHsv(0, 0, factor);
            painter.setBrush(brushColor);
            QPoint topLeft(x, y);
            QRect rect(topLeft, size);
            painter.drawRect(rect);
        }

    open_simplex_noise_free(ctx);
}

PicPainter::~PicPainter()
{

}
